//
//  MSPhoto.h
//  MSPhotoBrowser
//
//  Created by zzg on 2021/8/30.
//

#import <Foundation/Foundation.h>
#import <Photos/Photos.h>
#import "MSPhotoProtocol.h"

typedef void (^successBlock) (NSString *url);
typedef void (^successWithDataBlock) (NSString *url,NSData *data); //new successBlock
typedef void (^faileBlock) (NSError *error, NSString *url);
typedef void (^progressBlock) (float progress, NSString *url);


// This class models a photo/image and it's caption
// If you want to handle photos, caching, decompression
// yourself then you can simply ensure your custom data model
// conforms to MSPhotoProtocol
@interface MSPhoto : NSObject <MSPhoto>

@property (nonatomic, strong) NSString *caption;
@property (nonatomic, strong) NSURL *videoURL;
@property (nonatomic) BOOL emptyImage;
@property (nonatomic) BOOL isVideo;

@property (nonatomic, strong) NSURL *photoURL;
@property (nonatomic, strong) NSURL *photoOriginURL;        //原图地址
@property(nonatomic) int64_t originlSize;          //原图大小
@property (nonatomic) float progress;                       //origin photo progress
@property(nonatomic, assign) BOOL loadingInProgress;        //是否正在加载图片
@property(nonatomic, strong) UIImage *placeholderImage;     //占位图片

+ (MSPhoto *)photoWithImage:(UIImage *)image;
+ (MSPhoto *)photoWithImage:(UIImage *)image originUrl:(NSURL *)originUrl;
+ (MSPhoto *)photoWithURL:(NSURL *)url;
+ (MSPhoto *)photoWithURL:(NSURL *)url originURL:(NSURL *)originURL;
+ (MSPhoto *)photoWithImage:(UIImage *)image URL:(NSURL *)url originUrl:(NSURL *)originUrl;

+ (MSPhoto *)photoWithAsset:(PHAsset *)asset targetSize:(CGSize)targetSize;
+ (MSPhoto *)videoWithURL:(NSURL *)url; // Initialise video with no poster image

- (id)init;
- (id)initWithImage:(UIImage *)image;
- (id)initWithImage:(UIImage *)image originUrl:(NSURL *)originUrl;
- (id)initWithURL:(NSURL *)url;
- (id)initWithURL:(NSURL *)url originUrl:(NSURL *)originUrl;
- (id)initWithAsset:(PHAsset *)asset targetSize:(CGSize)targetSize;
- (id)initWithVideoURL:(NSURL *)url;

// 原图下载 内部使用SDWebImage框架下载
- (void)loadUnderlyingOriginImageAndNotifyWithProgress:(progressBlock)progressBlock
                                               success:(successWithDataBlock)successBlock
                                                 faile:(faileBlock)faileBlock;
@end

